package com.mrobuy.jdvc.dao.impl;

import com.mrobuy.jdvc.dao.SeachItemDao;
import com.mrobuy.jdvc.dao.VCBrandDao;
import com.mrobuy.jdvc.entity.SearchItem;
import com.mrobuy.jdvc.entity.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

@Repository("seachItemDao")
public class SeachItemDaoImpl implements SeachItemDao {

    private static Logger LOG = LoggerFactory.getLogger(SeachItemDao.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<SearchItem> query(String taskid) {
        try {
            List<SearchItem> searchItems = jdbcTemplate.query("SELECT * from SEARCHITEM where TASKID = ?", new Object[]{taskid}, new BeanPropertyRowMapper(SearchItem.class));
            return searchItems;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }

        return Collections.EMPTY_LIST;
    }
}
